package org.dromara.hmily.demo.springcloud.order.test;

import org.aopalliance.intercept.Interceptor;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @auther zzyy
 * @create 2021-04-11 17:11
 */
@Component
public class T2 implements HandlerInterceptor
{
    /**
     * 请求进入Controller前调用。
     * @param request
     * @param response
     * @param handler
     * @return
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    {
        System.out.println("T2-----preHandle HandlerInterceptor");
        return true;
    }

    /**
     * Controller的方法调用之后执行，在DispatcherServlet进行视图返回渲染之前被调用，
     * 所以可以在这个方法中对Controller处理之后的ModelAndView对象进行操作
     * @param request
     * @param response
     * @param handler
     * @param modelAndView
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                           ModelAndView modelAndView)
    {
        System.out.println("T2-----postHandle HandlerInterceptor");
    }

    /**
     * 在请求处理后，在DispatcherServlet渲染了对应的视图之后执行，进行资源清理工作。
     * @param request
     * @param response
     * @param handler
     * @param ex
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
    {
        System.out.println("T2-----afterCompletion HandlerInterceptor");
    }
}
